package com.cloudbroker.openapi.manage.controller;

import com.cloudbroker.bcs.common.entity.HSBCPSBackVO;
import com.cloudbroker.bcs.common.util.VOUtil;
import com.cloudbroker.bcs.platform.ltb.bizapi.service.leader.back.InviteLogBackVo;
import com.cloudbroker.bcs.platform.ltb.bizapi.service.leader.back.InviteLogList;
import com.cloudbroker.bcs.platform.ltb.bizapi.service.leader.back.LeaderBackVo;
import com.cloudbroker.bcs.platform.ltb.bizapi.service.leader.back.LeaderListBackVo;
import com.cloudbroker.bcs.platform.ltb.bizapi.service.leader.vo.InviteLogForm;
import com.cloudbroker.bcs.platform.ltb.bizapi.service.leader.vo.LeaderGetMessageForm;
import com.cloudbroker.bcs.platform.ltb.bizapi.service.user.vo.UserListQueryForm;
import com.cloudbroker.bcs.platform.ltb.bizapi.t2service.business.LeaderT2BizService;
import com.cloudbroker.bcs.platform.ltb.common.ext.annotation.SaveLog;
import com.cloudbroker.openapi.manage.util.ExcelUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.util.List;

import static com.cloudbroker.bcs.platform.ltb.common.util.RequestUtil.getSingleParameterMapForBody;

/**
 * Created by tianrui on 2016/7/14.
 */

@Controller
public class LeaderController {

    @Resource
    private LeaderT2BizService leaderT2BizService;

    @ResponseBody
    @RequestMapping("/leader_msg")
    @SaveLog(remark = "投顾信息")
    public LeaderBackVo leader_msg(HttpServletRequest request, String jsonpcallback){
        LeaderGetMessageForm form=getSingleParameterMapForBody(request,LeaderGetMessageForm.class);
        return VOUtil.setJsonpResult(leaderT2BizService.getLeaderMsg(form),jsonpcallback);
    }

    @ResponseBody
    @RequestMapping("/leader_list")
    @SaveLog(remark = "投顾信息")
    public LeaderListBackVo leader_msg_list(HttpServletRequest request, String jsonpcallback){
        UserListQueryForm form=getSingleParameterMapForBody(request,UserListQueryForm.class);
        return VOUtil.setJsonpResult(leaderT2BizService.getLeaderList(form),jsonpcallback);
    }


    @ResponseBody
    @RequestMapping("/invitelog_list")
    @SaveLog(remark = "投顾信息")
    public InviteLogList leader_invitelog_list(HttpServletRequest request, String jsonpcallback){
        InviteLogForm form=getSingleParameterMapForBody(request,InviteLogForm.class);
        return VOUtil.setJsonpResult(leaderT2BizService.fetchInviteLogs(form),jsonpcallback);
    }

    @ResponseBody
    @RequestMapping("/export_invite_log_list")
    public HSBCPSBackVO outputLeader(HttpServletRequest request, String jsonpcallback, HttpServletResponse response) {
        InviteLogForm form=getSingleParameterMapForBody(request,InviteLogForm.class);
        InviteLogList list = leaderT2BizService.fetchInviteLogs(form);
        if (list==null||!("0").equals(list.getError_no())||list.getData_list()==null) {
            return VOUtil.setJsonpResult(list,jsonpcallback);
        }
        List<InviteLogBackVo> data_list = list.getData_list();
        ExcelUtil.outputFile(response,data_list);
        return null;
    }

}
